<template>
  <div>
    <div style="display: flex">
      <el-tabs
        v-model="stepActive"
        :key="tabsKey"
        @tab-click="handleTabClick"
        stretch
        style="width: 100%"
      >
        <el-tab-pane label="基本资料" name="1" />
        <el-tab-pane label="临床工作" name="2" />
        <el-tab-pane label="考核记录" name="3" />
        <el-tab-pane label="个人小结" name="4" />
        <el-tab-pane label="进修评价" name="5" />
      </el-tabs>
      <div
        style="width: 150px; margin-left: 20px"
        v-if="form.graduationAuditStatus != 0"
      >
        <el-button type="link" @click="exportForm">导出手册</el-button>
      </div>
    </div>
    <el-form
      ref="manualForm"
      :model="registerManualVo"
      :rules="manualRules"
      label-width="160px"
    >
      <div v-if="stepActive == '1'">
        <div class="main-container photo-box">
          <img class="img" :src="baseURL + form.electronicIdPhoto" />
          <div>
            <div>
              <span style="font-weight: bolder">{{ form.userName }}</span
              >（{{ form.registerNoticeVo.jobNumber }}）
            </div>
            <div>进修科目：{{ form.registerDeptName }}</div>
            <div>
              进修日期：{{ form.registerNoticeVo.startDate }} -
              {{ form.registerNoticeVo.endDate }}
            </div>
            <div>单位名称：{{ form.unitHospitalName }}</div>
          </div>
        </div>
        <div class="main-container">
          <div class="header-title">出勤情况</div>
          <div class="leave-box">
            <div class="item">
              <div class="value">{{ personalDays }}</div>
              <div>事假(天)</div>
            </div>
            <div class="item">
              <div class="value">{{ sickDays }}</div>
              <div>病假(天)</div>
            </div>
            <div class="item">
              <div class="value">{{ closeDays }}</div>
              <div>销假(天)</div>
            </div>
            <div class="item">
              <div class="value">{{ realLeaveDays }}</div>
              <div>实际请假(天)</div>
            </div>
          </div>
        </div>
        <div class="main-container">
          <div class="header-title">个人档案</div>
          <div class="info-box">
            <el-row :gutter="15">
              <el-col :span="12">
                <div>联系电话：{{ form.phoneNumber }}</div>
                <div>
                  工作单位/等级：{{ form.unitName
                  }}<span style="margin-left: 10px" v-if="form.unitLevel"
                    >/ {{ form.unitLevel }}</span
                  >
                </div>
                <div>
                  单位地址：{{ form.unitProvince }}{{ form.unitCity
                  }}{{ form.unitDistrict }}{{ form.unitAddress }}
                </div>
                <div>邮编：{{ form.zipCode }}</div>
              </el-col>
              <el-col :span="12">
                <div>最高学历：{{ form.highestDegree }}</div>
                <div>职称：{{ form.technicalTitle }}</div>
                <div>单位电话：{{ form.workTelephone }}</div>
              </el-col>
            </el-row>
          </div>
          <div style="font-weight: bolder; font-size: 16px; margin: 10px 0">
            工作经历
          </div>
          <el-timeline>
            <el-timeline-item
              v-for="(item, index) in form.registerWorkVoList"
              :key="index"
            >
              <div>{{ item.startDate }} - {{ item.endDate || "至今" }}</div>
              <div>{{ item.hospitalName }}</div>
              <div>{{ item.duties }}</div>
            </el-timeline-item>
          </el-timeline>
        </div>
        <div class="main-container">
          <div class="header-title">本次进修的要求与目的</div>
          <div class="textarea-container">{{ form.educationAskObjective }}</div>
        </div>
      </div>
      <div v-if="stepActive == '2'">
        <div class="main-container">
          <div class="header-title">进修计划/记录</div>
          <el-table :data="[form]">
            <el-table-column
              label="进修期限"
              align="center"
              prop="durationStartDate"
            >
              <template slot-scope="scope">
                <div v-if="scope.row.registerNoticeVo">
                  {{ scope.row.registerNoticeVo.startDate }} -
                  {{ scope.row.registerNoticeVo.endDate }}
                </div>
                <div>{{ scope.row.durationName }}</div>
              </template>
            </el-table-column>
            <el-table-column
              label="进修科目"
              align="center"
              prop="registerDeptName"
            />
            <el-table-column
              label="带教老师"
              align="center"
              prop="registerAllocationVoList"
            >
              <template slot-scope="scope">
                <div
                  v-for="(item, index) in scope.row.registerAllocationVoList"
                  :key="index"
                >
                  {{ item.teacherNickName }}
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="main-container">
          <div class="header-title">临床工作记录</div>
          <div class="section-box">一、门急诊工作</div>
          <div class="item-1-2">
            <el-form-item label="门诊(天)" prop="clinicNumber">
              <el-input
                type="number"
                v-model.number="registerManualVo.clinicNumber"
                placeholder="请输入门诊(天)"
              />
            </el-form-item>
          </div>
          <div class="item-1-2">
            <el-form-item label="急诊(天)" prop="emergencyNumber">
              <el-input
                type="number"
                v-model.number="registerManualVo.emergencyNumber"
                placeholder="请输入急诊(天)"
              />
            </el-form-item>
          </div>
          <div class="item-1-2">
            <el-form-item label="平均每日诊病人(次)" prop="averageNumber">
              <el-input
                type="number"
                v-model.number="registerManualVo.averageNumber"
                placeholder="请输入平均每日诊病人(次)"
              />
            </el-form-item>
          </div>
          <el-form-item label="工作内容" prop="clinicEmergencyContent">
            <el-input
              type="textarea"
              :rows="5"
              v-model="registerManualVo.clinicEmergencyContent"
              placeholder="请输入工作内容"
            />
            <div class="tips">
              提示：门急诊工作可填写，如“参加抢救重危病人及病种”、“诊断性操作名称及次数”
            </div>
          </el-form-item>
          <div class="separate-box"></div>
          <div class="section-box">二、病房工作</div>
          <div class="item-1-2">
            <el-form-item label="管理床位(张)">
              <el-input
                type="number"
                v-model.number="registerManualVo.manageBeds"
                placeholder="请输入管理床位(张)"
              />
            </el-form-item>
          </div>
          <div class="item-1-2">
            <el-form-item label="写住院病例(份)">
              <el-input
                type="number"
                v-model.number="registerManualVo.caseNumber"
                placeholder="请输入写住院病例(份)"
              />
            </el-form-item>
          </div>
          <el-form-item label="病房工作内容">
            <el-input
              type="textarea"
              :rows="5"
              v-model="registerManualVo.wardContent"
              placeholder="请输入工作内容"
            />
            <div class="tips">
              提示：病房工作可填写，如“看到病种及例数”、“参加手术情况”、“手术名称及次数”
            </div>
          </el-form-item>
          <div class="separate-box"></div>
          <div class="section-box">三、业务学习</div>
          <el-form-item label="业务学习内容" prop="businessContent">
            <el-input
              type="textarea"
              :rows="5"
              v-model="registerManualVo.businessContent"
              placeholder="请输入学习内容"
            />
            <div class="tips">
              提示：业务学习可填写，如“业务学习的主要内容及次数”
            </div>
          </el-form-item>
          <div class="separate-box"></div>
          <div class="section-box">四、其他工作（非临床工作进修人员）</div>
          <el-form-item label="其他工作内容" prop="otherContent">
            <el-input
              type="textarea"
              :rows="5"
              v-model="registerManualVo.otherContent"
              placeholder="请输入其他工作内容"
            />
          </el-form-item>
        </div>
      </div>
      <div v-if="stepActive == '3'">
        <div class="main-container">
          <!-- <div class="header-title">带教考核</div> -->
          <!-- <el-empty
            v-if="form.registerAllocationVoList.length == 0"
            description="您还没有分配带教，没有考核信息！"
          ></el-empty> -->
          <div class="score-row">
            <div class="total-box">
              <el-row :gutter="30">
                <el-col :span="24">
                  <div class="header-title">
                    科室秘书评级<span class="desc"
                      >科室秘书评定进修考核的最终考评结论；考评结论分为四个等级：优、良、合格、不合格。</span
                    >
                  </div>

                  <div class="section">
                    <div>
                      评级人：{{ form.scoreLevelNickName || "未分配评级人" }}
                    </div>
                  </div>
                  <div
                    style="
                      display: flex;
                      align-items: center;
                      font-size: 16px;
                      margin-bottom: 10px;
                    "
                  >
                    <div>考评结论：</div>
                    <div
                      style="
                        font-size: 28px;
                        font-weight: bolder;
                        margin-top: 5px;
                      "
                    >
                      {{ form.scoreLevel || "暂未评级" }}
                    </div>
                    <div v-if="!form.scoreLevel" style="margin-left: 20px">
                      若进修科室结束前15天尚未评级，请提醒科室秘书评级
                    </div>
                  </div>
                </el-col>
                <el-col :span="24">
                  <div class="header-title">
                    带教老师评分<span class="desc"
                      >将由带教老师评定考核综合得分，总分100</span
                    >
                  </div>

                  <div class="section">
                    <div style="display: flex; align-items: center">
                      评分人：
                      <template v-if="form.registerAllocationVoList.length > 1">
                        <el-tooltip placement="top">
                          <div slot="content">
                            <div>考核综合得分:{{ form.scoreTotal }}</div>
                            <div
                              v-for="(
                                item, index
                              ) in form.registerAllocationVoList"
                              :key="index"
                            >
                              {{ item.teacherNickName }}: {{ item.scoreTotal }}
                            </div>
                          </div>
                          <span>
                            <template
                              v-for="(
                                item, index
                              ) in form.registerAllocationVoList"
                            >
                              {{ item.teacherNickName }}
                              <span
                                :key="index"
                                v-if="
                                  index <
                                  form.registerAllocationVoList.length - 1
                                "
                                >、</span
                              >
                            </template>
                          </span>
                        </el-tooltip>
                      </template>
                      <template
                        v-else-if="form.registerAllocationVoList.length == 1"
                      >
                        <template
                          v-for="(item, index) in form.registerAllocationVoList"
                        >
                          {{ item.teacherNickName }}
                          <span
                            v-if="
                              index < form.registerAllocationVoList.length - 1
                            "
                            >、</span
                          >
                        </template>
                      </template>
                      <template v-else>
                        <div style="display: flex">
                          <span>未分配带教老师</span
                          ><span style="margin-left: 20px"
                            >若进修结束前15天尚未分配带教老师，请提醒科室分配</span
                          >
                        </div>
                      </template>
                    </div>
                  </div>
                  <div
                    style="display: flex; align-items: center; font-size: 16px"
                  >
                    <template v-if="form.registerAllocationVoList.length > 1">
                      <el-tooltip placement="top">
                        <div
                          slot="content"
                          style="
                            font-size: 28px;
                            font-weight: bolder;
                            margin-top: 5px;
                          "
                        >
                          <div>考核综合得分:{{ form.scoreTotal }}</div>

                          <div
                            v-for="(
                              item, index
                            ) in form.registerAllocationVoList"
                            :key="index"
                          >
                            {{ item.teacherNickName }}: {{ item.scoreTotal }}
                          </div>
                        </div>
                        <span
                          >考核综合得分：<span
                            style="
                              font-size: 28px;
                              font-weight: bolder;
                              margin-top: 5px;
                            "
                            >{{ form.scoreTotal }}</span
                          ></span
                        >
                      </el-tooltip>
                    </template>
                    <template v-else style="display: flex; align-items: center">
                      <div
                        style="
                          font-size: 28px;
                          font-weight: bolder;
                          margin-top: 5px;
                        "
                      >
                        <span
                          style="
                            font-size: 16px;
                            font-weight: normal;
                            margin-right: 20px;
                          "
                          >考核综合得分:</span
                        >{{ form.scoreTotal || "暂未评分" }}
                      </div>
                      <div v-if="!form.scoreLevel" style="margin-left: 20px">
                        若进修科室结束前15天尚未评分，请提醒带教老师评分
                      </div>
                    </template>
                  </div>
                  <div style="margin: 10px 0">
                    <el-progress
                      :text-inside="true"
                      :stroke-width="15"
                      :percentage="form.scoreTotal || 0"
                    ></el-progress>
                  </div>
                </el-col>
              </el-row>
            </div>
            <div class="score-row-item">
              <div class="left">
                <div class="title">职业道德 (15分)</div>
                <div class="desc">
                  遵守医德规范、廉洁自律、合理医疗、尊重患者
                </div>
              </div>
              <div class="right">
                <el-tooltip placement="top">
                  <div slot="content">
                    <div
                      v-for="(item, index) in form.registerAllocationVoList"
                      :key="index"
                    >
                      {{ item.teacherNickName }}: {{ item.scoreProfessional }}
                    </div>
                  </div>
                  <span>{{ registerAllocationVo.scoreProfessional }}</span>
                </el-tooltip>
              </div>
            </div>

            <div class="score-row-item">
              <div class="left">
                <div class="title">劳动纪律 (20分)</div>
                <div class="desc">准时上下班，服从科室安排，坚守工作岗位</div>
              </div>
              <div class="right">
                <el-tooltip placement="top">
                  <div slot="content">
                    <div
                      v-for="(item, index) in form.registerAllocationVoList"
                      :key="index"
                    >
                      {{ item.teacherNickName }}: {{ item.scoreLabour }}
                    </div>
                  </div>
                  <span>{{ registerAllocationVo.scoreLabour }}</span>
                </el-tooltip>
              </div>
            </div>

            <div class="score-row-item">
              <div class="left">
                <div class="title">工作责任性 (15分)</div>
                <div class="desc">
                  积极参加科室业务学习、无医疗责任事故及严重差错
                </div>
              </div>
              <div class="right">
                <el-tooltip placement="top">
                  <div slot="content">
                    <div
                      v-for="(item, index) in form.registerAllocationVoList"
                      :key="index"
                    >
                      {{ item.teacherNickName }}: {{ item.scoreDuty }}
                    </div>
                  </div>
                  <span>{{ registerAllocationVo.scoreDuty }}</span>
                </el-tooltip>
              </div>
            </div>

            <div class="score-row-item">
              <div class="left">
                <div class="title">操作能力 (30分)</div>
                <div class="desc">
                  完成科室规定的临床工作量及要求掌握的诊疗技能
                </div>
              </div>
              <div class="right">
                <el-tooltip placement="top">
                  <div slot="content">
                    <div
                      v-for="(item, index) in form.registerAllocationVoList"
                      :key="index"
                    >
                      {{ item.teacherNickName }}: {{ item.scoreOperate }}
                    </div>
                  </div>
                  <span>{{ registerAllocationVo.scoreOperate }}</span>
                </el-tooltip>
              </div>
            </div>

            <div class="score-row-item">
              <div class="left">
                <div class="title">病史报告书写 (20分)</div>
                <div class="desc">
                  能按照要求规范书写病史、辅助科室检查记录、报告等
                </div>
              </div>
              <div class="right">
                <el-tooltip placement="top">
                  <div slot="content">
                    <div
                      v-for="(item, index) in form.registerAllocationVoList"
                      :key="index"
                    >
                      {{ item.teacherNickName }}: {{ item.scoreMedicalHistory }}
                    </div>
                  </div>
                  <span>{{ registerAllocationVo.scoreMedicalHistory }}</span>
                </el-tooltip>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div v-if="stepActive == '4'">
        <div class="main-container">
          <div class="header-title">个人小结</div>
          <el-form-item label="个人小结" prop="personalSummary">
            <el-input
              type="textarea"
              :rows="10"
              v-model="registerManualVo.personalSummary"
              placeholder="请输入个人小结"
            />
          </el-form-item>
        </div>
      </div>
      <div v-if="stepActive == '5'">
        <div class="main-container">
          <div class="header-title">进修学员对学科培训工作的评估</div>
          <div class="section-box">一、进修学员入科前培训</div>
          <div class="row-box">
            <el-form-item label="" prop="introduceFlag" label-width="0">
              <el-row>
                <el-col :span="20">1、入科时学科基本情况介绍</el-col>
                <el-col :span="4">
                  <el-radio-group v-model="registerManualVo.introduceFlag">
                    <el-radio :label="1">是</el-radio>
                    <el-radio :label="2">否</el-radio>
                  </el-radio-group>
                </el-col>
              </el-row>
            </el-form-item>
            <el-form-item label="" prop="planFlag" label-width="0">
              <el-row>
                <el-col :span="20">2、提出明确的培训计划</el-col>
                <el-col :span="4">
                  <el-radio-group v-model="registerManualVo.planFlag">
                    <el-radio :label="1">是</el-radio>
                    <el-radio :label="2">否</el-radio>
                  </el-radio-group>
                </el-col>
              </el-row>
            </el-form-item>
            <el-form-item label="" prop="environmentFlag" label-width="0">
              <el-row>
                <el-col :span="20">3、学科告知工作流程及医疗环境</el-col>
                <el-col :span="4">
                  <el-radio-group v-model="registerManualVo.environmentFlag">
                    <el-radio :label="1">是</el-radio>
                    <el-radio :label="2">否</el-radio>
                  </el-radio-group>
                </el-col>
              </el-row>
            </el-form-item>
          </div>
          <div class="separate-box"></div>
          <div class="section-box">二、进修学员入科后教学管理</div>
          <div class="row-box">
            <el-form-item label="" prop="teacherFlag" label-width="0">
              <el-row>
                <el-col :span="20">1、安排临床上级带教老师</el-col>
                <el-col :span="4">
                  <el-radio-group v-model="registerManualVo.teacherFlag">
                    <el-radio :label="1">是</el-radio>
                    <el-radio :label="2">否</el-radio>
                  </el-radio-group>
                </el-col>
              </el-row>
            </el-form-item>
            <el-form-item label="" prop="businessFlag" label-width="0">
              <el-row>
                <el-col :span="20">2、学科安排进修学员参与业务学习</el-col>
                <el-col :span="4">
                  <el-radio-group v-model="registerManualVo.businessFlag">
                    <el-radio :label="1">是</el-radio>
                    <el-radio :label="2">否</el-radio>
                  </el-radio-group>
                </el-col>
              </el-row>
            </el-form-item>
            <el-form-item label="" prop="timecardFlag" label-width="0">
              <el-row>
                <el-col :span="20">3、学科对进修学员的考勤</el-col>
                <el-col :span="4">
                  <el-radio-group v-model="registerManualVo.timecardFlag">
                    <el-radio :label="1">是</el-radio>
                    <el-radio :label="2">否</el-radio>
                  </el-radio-group>
                </el-col>
              </el-row>
            </el-form-item>
          </div>
          <div class="separate-box"></div>
          <div class="section-box">三、进修学员培训结束学科鉴定</div>
          <div class="row-box">
            <el-form-item label="" prop="examineFlag" label-width="0">
              <el-row>
                <el-col :span="20">1、学科对进修学员的临床考核记录</el-col>
                <el-col :span="4">
                  <el-radio-group v-model="registerManualVo.examineFlag">
                    <el-radio :label="1">是</el-radio>
                    <el-radio :label="2">否</el-radio>
                  </el-radio-group>
                </el-col>
              </el-row>
            </el-form-item>
          </div>
          <div class="separate-box"></div>
          <div class="section-box">四、总体评价</div>
          <el-row class="row-box">
            <el-col :span="24"
              >1、您认为该学科具有哪些方面的实力
              (临床技术、学术氛围和学科管理等) ?</el-col
            >
            <el-col :span="24" style="margin-top: 15px">
              <el-form-item label="" prop="strengthContent" label-width="0">
                <el-input
                  type="textarea"
                  :rows="5"
                  v-model="registerManualVo.strengthContent"
                  placeholder="请输入"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="row-box">
            <el-col :span="24">2、您认为该学科哪些方面需要改进?</el-col>
            <el-col :span="24" style="margin-top: 15px">
              <el-form-item label="" prop="improveContent" label-width="0">
                <el-input
                  type="textarea"
                  :rows="5"
                  v-model="registerManualVo.improveContent"
                  placeholder="请输入"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </div>
    </el-form>
    <div class="footer">
      <el-button
        type="primary"
        @click="submitForm"
        :loading="submitLoading"
        v-if="!read"
        >保 存</el-button
      >
      <el-button type="link" @click="cancelForm">取 消</el-button>
    </div>
  </div>
</template>

<script>
import { getRegisterInfo } from "@/api/business/registerInfo";
import {
  addRegisterManual,
  updateRegisterManual,
} from "@/api/business/registerManual";

export default {
  props: {
    registerId: null,
    onlyread: false,
    index: {
      type: String,
      default: "1",
    },
  },
  data() {
    return {
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      form: {
        registerNoticeVo: {},
        registerLeaveVoList: [],
        registerManualVo: {},
        registerAllocationVoList: [],
      },
      tabsKey: 0,
      stepActive: "1",
      leaveDuration: 0,
      expiredDuration: 0,
      read: false,
      realLeaveDays: 0, // 真实请假天数
      sickDays: 0, // 病假天数
      personalDays: 0, // 事假天数
      closeDays: 0, // 销假天数
      submitLoading: false, // 添加提交loading状态
      // 培养手册
      registerManualVo: {},
      manualRules: {
        id: [{ required: true, message: "主键不能为空", trigger: "blur" }],
        registerId: [
          { required: true, message: "报名信息ID不能为空", trigger: "blur" },
        ],
        businessContent: [
          { required: true, message: "业务学习内容不能为空", trigger: "blur" },
        ],
        otherContent: [
          { required: true, message: "其他工作内容不能为空", trigger: "blur" },
        ],
        personalSummary: [
          { required: true, message: "个人小结不能为空", trigger: "blur" },
        ],
        introduceFlag: [{ required: true, message: "请选择", trigger: "blur" }],
        planFlag: [{ required: true, message: "请选择", trigger: "blur" }],
        environmentFlag: [
          { required: true, message: "请选择", trigger: "blur" },
        ],
        teacherFlag: [{ required: true, message: "请选择", trigger: "blur" }],
        businessFlag: [{ required: true, message: "请选择", trigger: "blur" }],
        timecardFlag: [{ required: true, message: "请选择", trigger: "blur" }],
        examineFlag: [{ required: true, message: "请选择", trigger: "blur" }],
        strengthContent: [
          { required: true, message: "实力评价不能为空", trigger: "blur" },
        ],
        improveContent: [
          { required: true, message: "改进评价不能为空", trigger: "blur" },
        ],
      },
      // 考核记录
      registerAllocationVo: {
        scoreProfessional: null,
        scoreLabour: null,
        scoreDuty: null,
        scoreOperate: null,
        scoreMedicalHistory: null,
      },
    };
  },
  watch: {
    "form.graduationAuditStatus": {
      handler(val) {
        if (val != null) {
          this.formLoaded = true;
          this.$nextTick(() => {
            this.tabsKey++; // 强制重新渲染
            this.updateTabUnderline();
          });
        }
      },
      immediate: true,
    },
  },
  mounted() {
    this.getInfo();
    this.stepActive = this.index;
  },
  methods: {
    updateTabUnderline() {
      this.$nextTick(() => {
        const tabs = this.$refs.tabs;
        if (tabs) {
          tabs.$children[0].$refs.nav.$children[0].update();
        }
      });
    },
    handleTabClick() {
      this.updateTabUnderline();
    },
    getInfo() {
      getRegisterInfo(this.registerId).then((response) => {
        this.form = response.data;
        if (response.data.leaveStat) {
          this.realLeaveDays = response.data.leaveStat.realLeaveDays;
          this.personalDays = response.data.leaveStat.personalDays;
          this.sickDays = response.data.leaveStat.sickDays;
          this.closeDays = response.data.leaveStat.closeDays;
        }
        this.leaveStatusDesc = response.data.leaveStatusDesc;
        // 如果不是只读,并且考核状态为待审核、审核通过、审核不通过,那么设置为只读
        if (
          !this.onlyread &&
          [1, 2, 3].indexOf(this.form.graduationAuditStatus) > -1
        ) {
          this.read = true;
        }

        if (this.form.registerManualVo) {
          this.registerManualVo = this.form.registerManualVo;
        } else {
          this.registerManualVo = {
            id: null,
            registerId: this.registerId,
            clinicNumber: null,
            emergencyNumber: null,
            averageNumber: null,
            clinicEmergencyContent: null,
            manageBeds: null,
            caseNumber: null,
            wardContent: null,
            businessContent: null,
            otherContent: null,
            personalSummary: null,
            introduceFlag: null,
            planFlag: null,
            environmentFlag: null,
            teacherFlag: null,
            businessFlag: null,
            timecardFlag: null,
            examineFlag: null,
            strengthContent: null,
            improveContent: null,
          };
        }
        for (let i = 0; i < this.form.registerLeaveVoList.length; i++) {
          let item = this.form.registerLeaveVoList[i];
          this.leaveDuration += item.leaveDuration;
          if (item.effectiveStatus == 1) {
            this.expiredDuration += item.leaveDuration;
          }
        }
        let scoreProfessional = 0;
        let scoreLabour = 0;
        let scoreDuty = 0;
        let scoreOperate = 0;
        let scoreMedicalHistory = 0;
        let allocationLength = this.form.registerAllocationVoList.length;
        for (let i = 0; i < allocationLength; i++) {
          let item = this.form.registerAllocationVoList[i];
          scoreProfessional += item.scoreProfessional;
          scoreLabour += item.scoreLabour;
          scoreDuty += item.scoreDuty;
          scoreOperate += item.scoreOperate;
          scoreMedicalHistory += item.scoreMedicalHistory;
        }
        // 防止除数为0导致NaN
        this.registerAllocationVo.scoreProfessional = allocationLength
          ? scoreProfessional / allocationLength
          : "/";
        this.registerAllocationVo.scoreLabour = allocationLength
          ? scoreLabour / allocationLength
          : "/";
        this.registerAllocationVo.scoreDuty = allocationLength
          ? scoreDuty / allocationLength
          : "/";
        this.registerAllocationVo.scoreOperate = allocationLength
          ? scoreOperate / allocationLength
          : "/";
        this.registerAllocationVo.scoreMedicalHistory = allocationLength
          ? scoreMedicalHistory / allocationLength
          : "/";
      });
    },
    // 导出手册
    exportForm() {
      this.$loading({
        lock: true,
        text: "下载中,请稍等",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.1)",
      });
      const url =
        this.baseURL +
        "/business/registerBase/exportManualPdf?id=" +
        this.form.id;
      fetch(url)
        .then((response) => response.blob())
        .then((blob) => {
          const a = document.createElement("a");
          const objectUrl = URL.createObjectURL(blob);
          a.href = objectUrl;
          a.download = "manual.pdf";
          document.body.appendChild(a);
          a.click();
          document.body.removeChild(a);
          URL.revokeObjectURL(objectUrl);
        })
        .finally(() => {
          this.$loading().close();
        });
    },
    cancelForm() {
      this.$emit("close");
    },
    // 保存手册
    submitForm() {
      if (this.submitLoading) return; // 防止重复提交

      this.$refs["manualForm"].validate((valid) => {
        if (valid) {
          this.submitLoading = true;

          if (this.registerManualVo.id != null) {
            updateRegisterManual(this.registerManualVo)
              .then((response) => {
                this.$modal.msgSuccess("保存成功");
                this.$emit("close");
              })
              .catch((error) => {
                console.error("更新失败:", error);
                this.$modal.msgError("保存失败，请重试");
              })
              .finally(() => {
                this.submitLoading = false;
              });
          } else {
            addRegisterManual(this.registerManualVo)
              .then((response) => {
                this.$modal.msgSuccess("保存成功");
                this.$emit("close");
              })
              .catch((error) => {
                console.error("新增失败:", error);
                this.$modal.msgError("保存失败，请重试");
              })
              .finally(() => {
                this.submitLoading = false;
              });
          }
        } else {
          this.$modal.msgError("请完善表单内容");
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.textarea-container {
  font-family: "Microsoft YaHei";
  white-space: pre-line;
  height: 200px;
  padding: 15px;
  border: 1px solid #f2f3f5;
  border-radius: 10px;
  overflow-y: auto;
}

::v-deep .el-tabs__item {
  font-size: 18px;
  font-weight: bolder;
}

.main-container {
  width: 1000px;
  margin-left: calc((100% - 1000px) / 2);
  margin-bottom: 15px;
  padding: 15px;
  background-color: white;
  border-radius: 10px;
  box-shadow: 5px 5px 10px 0 rgba(157, 156, 156, 0.1);
}

.header-title {
  background-color: #f2f3f5;
  height: 50px;
  line-height: 50px;
  font-weight: bolder;
  font-size: 18px;
  padding-left: 15px;
  border-left: 6px solid #a52529;
  border-radius: 5px;
  margin-bottom: 15px;
  display: flex;

  .desc {
    color: #979393;
    font-size: 14px;
    font-weight: bolder;
    margin-left: 20px;
    .red {
      color: #a52529;
    }
  }

  .download {
    color: #409eff;
    font-size: 16px;
    font-weight: normal;
    cursor: pointer;
  }
}

.photo-box {
  display: flex;
  line-height: 30px;

  .img {
    width: 100px;
    height: 120px;
    border: 1px solid #f2f3f5;
    margin-right: 20px;
  }
}

.leave-box {
  display: flex;
  line-height: 30px;

  .item {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 10px;
    min-width: 100px;
    height: 100px;
    margin-right: 20px;
    background-color: #f2f3f5;
    border-radius: 10px;

    .value {
      font-size: 22px;
      font-weight: bolder;
    }
  }
}

.info-box {
  line-height: 30px;
}

.section-box {
  font-size: 16px;
  font-weight: bolder;
  margin-bottom: 10px;
}

.item-1-2 {
  width: 50%;
}

.tips {
  color: rgb(139 139 139);
}

.separate-box {
  margin: 10px 0;
  border-bottom: 2px dashed #f2f3f5;
}

.score-row {
  .total-box {
    padding-bottom: 15px;
    border-bottom: 2px dashed #f2f3f5;

    .section {
      line-height: 30px;
      font-size: 16px;
      display: flex;
    }
  }

  .score-row-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px dashed #f2f3f5;
    padding: 10px 0;

    .left {
      .title {
        text-align: left;
        font-size: 18px;
        margin-bottom: 15px;
      }
    }

    .right {
      text-align: center;
      font-size: 18px;
      font-weight: bolder;
    }
  }
}

.row-box {
  margin: 0 25px;
}
.footer {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 60px;
  background-color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  border-top: 1px solid #f2f3f5;
  box-shadow: 0 -2px 10px 0 rgba(157, 156, 156, 0.1);
}
</style>
